package sns.action;

import org.springframework.transaction.annotation.Transactional;

import sns.bean.Tag;
import sns.dao.TagDao;
import sns.dao.UserDao;

import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionSupport;

@SuppressWarnings("serial")
public class AddTagAction extends ActionSupport {

	// injection
	private TagDao tagDao;
	private UserDao userDao;
	// pass in
	private Long visitId;
	private String tagContent;

	// return
	// private Long visitId;
	
	@Transactional
	public String execute() {

		if (visitId == null) {
			System.out.println("No visit id.");
			return ActionSupport.INPUT;
		}
		Tag tag = new Tag();
		tag.setTagtxt(tagContent);
		tag.setTagUser(userDao.findUserById(visitId));
		tagDao.save(tag);

		return Action.SUCCESS;
	}

	public Long getVisitId() {
		return visitId;
	}

	public void setVisitId(Long visitId) {
		this.visitId = visitId;
	}

	public void setTagDao(TagDao tagDao) {
		this.tagDao = tagDao;
	}

	public void setUserDao(UserDao userDao) {
		this.userDao = userDao;
	}

	public void setTagContent(String tagContent) {
		this.tagContent = tagContent;
	}
}
